package com.woniuxy.lab.woniu_lab_boss.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.woniuxy.lab.woniu_lab_boss.dao.UserDao;
import com.woniuxy.lab.woniu_lab_boss.model.Order;
import com.woniuxy.lab.woniu_lab_boss.dao.OrderDao;
import com.woniuxy.lab.woniu_lab_boss.model.User;
import com.woniuxy.lab.woniu_lab_boss.service.OrderService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.woniuxy.lab.woniu_lab_boss.service.dto.OrderDto;
import com.woniuxy.lab.woniu_lab_boss.service.dto.TeacherDto;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * <p>
 * 消费记录表 服务实现类
 * </p>
 *
 * @author Silas
 * @since 2023-03-15
 */
@Service
public class OrderServiceImpl extends ServiceImpl<OrderDao, Order> implements OrderService {
@Resource
private OrderDao orderDao;
@Resource
private UserDao userDao;
    @Override
    public IPage<OrderDto> queryVip(Integer page, Integer size) {
        IPage<Order> iPage = new Page<>(page == null ? 1 : page, size == null ? 4 : size);
        IPage<Order> orderIPage = orderDao.selectPage(iPage,
                new QueryWrapper<Order>().eq("info", "VIP")
                        .or().eq("info", "SVIP"));

        return orderIPage.convert(u->{
            OrderDto orderDto = new OrderDto();
            BeanUtils.copyProperties(u, orderDto);
            User user = userDao.selectById(orderDto.getUserId());
            orderDto.setNickname(user.getNickname());
            return orderDto;
        });
    }
}
